package com.fengmi.mapper;

import com.fengmi.entity.SysPermission;
import com.fengmi.entity.SysRole;
import com.fengmi.entity.SysUser;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author 123
 * @Date 2022/2/10 11:24
 * @Version 1.0
 */

public interface UserMapper {

    // 通过用户名查询用户
    @Select("select * from sys_user where user_name = #{userName}")
    public SysUser findUserByUserName(String userName);


    @Select("SELECT r.* FROM \n" +
            "sys_user u\n" +
            "LEFT JOIN sys_user_role sr ON sr.user_id = u.user_id\n" +
            "LEFT JOIN sys_role r ON r.role_code = sr.role_id\n" +
            "WHERE u.user_id = #{userId}")
    public List<SysRole> findRolesByUserId(String userId);


    @Select("SELECT sp.* FROM \n" +
            "sys_user u\n" +
            "LEFT JOIN sys_user_role sr ON sr.user_id = u.user_id\n" +
            "LEFT JOIN sys_role r ON r.role_code = sr.role_id\n" +
            "LEFT JOIN sys_role_permission srp ON srp.role_id = sr.role_id\n" +
            "LEFT JOIN sys_permission sp ON sp.perm_code = srp.perm_id\n" +
            "WHERE u.user_id = #{userID}")
    public List<SysPermission> findPermissionByUserId(String userID);
}
